Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor prior construction and make clearer the logic #566

Merged
merged 4 commits into from
Dec 23, 2024

Conversation

SamuelBrand1
Copy link
Collaborator

This PR is (hopefully) an improvement to #565 aimed at addressing @seabbs concerns about the implementation. Concerns I share because I think the opaque implementation got in the way of me implementing the priors I wanted (and @seabbs reviewing them from a scientific point of view).

Copy link
Contributor

Try this Pull Request!

Open Julia and type:

import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/CDCgov/Rt-without-renewal", rev="new-way-to-specify-priors", subdir="EpiAware")
using EpiAware

@SamuelBrand1
Copy link
Collaborator Author

The idea of this approach is that the remake_latent_model function first calls down to an internal function that sets our expectation of the fluctuations (std) and autocorr based on the IGP and whether the latent process representation is stationary or not.

This passes to a function which then constructs the latent process in one of two ways:

  • If stationary, it aims to (approximately) get the stationary std and autocorr as prior expected.
  • if non-stationary its this but aimed at the step by step fluctuations.

The autocorrelation is expected to be 0.1.
"""
function _make_target_std_and_autocorr(igp; stationary::Bool)
if igp == Renewal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This much nicer but my training for you makes me want it to dispatch down based on igp vs ifelse it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha thing here is that igp is the type itself rather and an instance of a type so got to remember how to do that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it was indeed nicer!

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.96%. Comparing base (1b3d397) to head (dd689bd).

Additional details and impacted files
@@               Coverage Diff                @@
##           specific-priors     #566   +/-   ##
================================================
  Coverage            90.96%   90.96%           
================================================
  Files                   60       60           
  Lines                  863      863           
================================================
  Hits                   785      785           
  Misses                  78       78           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is much nicer. I think it could get even nicer but happy with it as it is

@SamuelBrand1
Copy link
Collaborator Author

priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels DirectInfections_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels DirectInfections_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels DirectInfections_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels ExpGrowthRate_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels ExpGrowthRate_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels ExpGrowthRate_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=10 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=10 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=10 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=20 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=20 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=20 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70

@SamuelBrand1
Copy link
Collaborator Author

Some of those priors look too confident at no outbreak

@SamuelBrand1 SamuelBrand1 requested a review from seabbs December 20, 2024 14:00
@SamuelBrand1
Copy link
Collaborator Author

As ever, Julia rewards thinking about dispatch. I think this version is getting there. Ready for re-review and sci review

@seabbs
Copy link
Collaborator

seabbs commented Dec 20, 2024

Nice:

Prior predictive review:

  • Direct infections looks too tight
  • AR for Expontial growth is a bit tight
  • Otherwise I think this is looking reasonable

Copy link
Collaborator

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation wise I think this is nice enough now (though I think there are a few alternative patterns that better match our more general approach and worth thinking about why/if they aren't easy to do).

So just the science to discuss now

@SamuelBrand1
Copy link
Collaborator Author

Nice:

Prior predictive review:

  • Direct infections looks too tight
  • AR for Expontial growth is a bit tight
  • Otherwise I think this is looking reasonable

Agree with all this

@SamuelBrand1
Copy link
Collaborator Author

Bumped the variance for models mentioned by @seabbs above. Think it looks ok... Obviously same $\log R_t$ gives very different dynamics with different mean GI in the Renewal model.

@SamuelBrand1
Copy link
Collaborator Author

priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels DirectInfections_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels DirectInfections_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels DirectInfections_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels ExpGrowthRate_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels ExpGrowthRate_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels ExpGrowthRate_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=2 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=10 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=10 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=10 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=20 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=20 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=diff_ar_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70
priorpred_gi_mean=20 0_gi_std=2 0_igp=EpiAware EpiInfModels Renewal_latent_model=rw_priorpredictive=true_scenario=SmoothOutbreakPipeline_tspan=1_70

@SamuelBrand1 SamuelBrand1 requested a review from seabbs December 20, 2024 15:29
Copy link
Collaborator

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this looks good now

@seabbs seabbs merged commit af6dfb6 into specific-priors Dec 23, 2024
10 checks passed
@seabbs seabbs deleted the new-way-to-specify-priors branch December 23, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants